//
//  AIDiaryReplayBean.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/3/11.
//
/**
 * 聊天
 */
import Foundation
import SwiftUI
class AIChatRequestBean : Identifiable ,Codable {
    
    var max_tokens: Int64 = configManager.getConfig().AiConfig.maxTokens ?? 1024
    var temperature: Float64 = configManager.getConfig().AiConfig.temperature ?? 0.9
    var top_p: Float64 = configManager.getConfig().AiConfig.top_p ?? 0.95
    var stream = false
    var messages: [MessagesV2]
    var model :String
    
    
    init(active:Bool, model: String?, list : [ChatBean], botRoleBean: RoleBean) {
        self.model = model ?? ""
        let userRoleBean = RoleBean.get(userManager.user, botRoleBean)
        self.messages = AIChatRequestBean.getMessagesList(active: active, list: list, botRoleBean: botRoleBean, userRoleBean: userRoleBean,model : model)
    }
    
    private static func getMessagesList(active:Bool, list : [ChatBean], botRoleBean: RoleBean,
                                        userRoleBean: RoleBean, model: String?) ->[MessagesV2] {
        
        let time = Date().timeIntervalSince1970
        if AppStorageManager.shared.toggleChatFunc {
            //互动模式
            return ChatContentUtils.getMessagesNewList(active: active, list: list, botRoleBean: botRoleBean, userRoleBean: userRoleBean, time: time, model: model)
        } else {
            return ChatContentUtils.getMessagesList(active: active, list: list, botRoleBean: botRoleBean, userRoleBean: userRoleBean, time: time, model: model)
        }
    }
    
    
}
